package org.dei.perla.sys.registry;

import java.util.ArrayList;
import org.dei.perla.parser.expressions.*;
import org.dei.perla.parser.statements.*;
import org.dei.perla.sys.device.fpc.FPC;
import org.dei.test.llqruntime.stack.FPCmockup;


/**
 * MOCKUP DEL REGISTRY
 * @author diego
 *
 */
public class Registry {
	
	private static ArrayList<FPC> pActiveFPCs = new ArrayList<FPC>();
	
	public static ArrayList<FPC> askRegistryForFPCs(LLStatement parStatement) {
		ArrayList<FPC> tArrayToReturn = new ArrayList<FPC>();
		Node tClause = parStatement.getExecuteIfClause().getCondition();
		if (tClause instanceof NodeExistsAttribute) 
			{
			String tAttrName = ((NodeExistsAttribute) tClause).getExistsAttribute().getLogicalObjectAttributeName();
			
			for (FPC tFPC : pActiveFPCs) {
				((FPCmockup) tFPC).getFPCAttributes();
				if (((FPCmockup) tFPC).getFPCAttributes().getRecordStructure().containsKey(tAttrName)) {
					((FPCmockup) tFPC).registerQueryOnFPC(parStatement);
					tArrayToReturn.add((FPCmockup)tFPC);
				}
			}
			
			}
		return tArrayToReturn;
	}
	
	public static void registerThisFPC(FPC parFPC) {
		pActiveFPCs.add(parFPC);
	}
}
